<template>
  <view class="wrapper pd_l_30">
    <u-cell-group v-if="!searchFlag">
      <u-cell-item :title="item.third_spe_name" :value="select ? '选择该专业' : '详细信息'" v-for="(item, index) in list"
                   :key="index" @click="toDetail(item.third_spe_code, item.third_spe_name)"></u-cell-item>
    </u-cell-group>
    <block v-if="searchFlag">
      <u-cell-group v-if="list.length">
        <u-cell-item :title="`${item.thirdSpeName}(${item.specialtyType})`" :value="select ? '选择该专业' : '详细信息'" v-for="(item, index) in list"
                     :key="index" @click="toDetail(item.thirdSpeCode, item.thirdSpeName, item.specialtyType)"></u-cell-item>
      </u-cell-group>
      <view style="height: 90vh" class="u-flex u-flex-col flex-center" v-if="!list.length">
        <u-empty text="暂无相关搜索结果" mode="search"></u-empty>
      </view>
    </block>
  </view>
</template>

<script>
  import {request} from "../../util/api";
  import {getCurrentFullPath, TOAST} from "../../util/util";

  export default {
    onLoad(option) {
      uni.setNavigationBarTitle({
        title: option.name || ''
      });
      this.code = option.code
      if (option.code) {
        this.getList()
      }
      if (option.s) {
        uni.setNavigationBarTitle({
          title: `【${option.k}】搜索结果` || ''
        });
        this.search(option.k)
        this.searchFlag = true
      }

      if (option.data) {
        this.select = true
        this.fill_data = JSON.parse(option.data)
      }
    },

    data() {
      return {
        code: '',
        list: [],
        searchFlag: false,
        select: false,
        fill_data: {}
      }
    },

    methods: {
      toDetail(index, name, type) {
        this.fill_data.specialtyName = name
        if (type) {
          this.fill_data.uOrS = type
        }
        this.$u.route({
          url: this.select ? `/pages/explore/fill_in?data=${JSON.stringify(this.fill_data)}&code=${index}` : '/pages/explore/zhuanye_detail?code=' + index,
          type: this.select ? 'reLaunch' : 'navigateTo'
        })
      },

      search(k) {
        request({
          url: '/system/wx/CompassSpecialty/getInfoByThirdSpeName/' + k,
          token: true
        }).then(res => {
          console.log(res)
          this.list = res.data
        })
      },

      getList() {
        request({
          url: '/system/wx/CompassSpecialty/getThirdSpecialtyList/' + this.code,
          token: true
        }).then(res => {
          this.list = res.data
          console.log(this.list)
        })
      },
      onShareAppMessage(res) {
        return {
          path: getCurrentFullPath()
        }
      }
    }
  }
</script>

<style scoped lang="scss">

</style>
